<?php
require_once  '../classes/DisciplinaManager.php';
require_once  '../classes/DisciplinaDataManager.php';
require_once  '../classes/ConnectionDB.php';
require_once '../bean/Disciplina.php';
require_once '../classes/LoadProperties.php';
$properties = new LoadProperties();
$properties->initErrors();
$properties->initServices();
$db =ConnectionDB::getInstance()->connectToDB();
$result = DisciplinaManager::getInstance()->getDiscipline($db);

if(!isset ($_GET["codiceUtente"]))
    $disciplineUtente = DisciplinaDataManager::getInstance()->getDisciplineUtente($db);
else
    $disciplineUtente = DisciplinaDataManager::getInstance()->getDisciplineByUtente($db, $_GET["codiceUtente"]);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Discipline utente</title>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
        <style type="text/css">

            @import url("../css/style.css");

            #disciplineBox
            {
                padding-top: 3%;
            }
        </style>
        <script>
            path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
            window.onload = function(){

                var disciplineBox = new GlassBox();
                disciplineBox.init( 'disciplineBox', '620px', '110px', 'hidden','',true, false);
                disciplineBox.ipos();
                disciplineBox.appear();

                var disciplineResBox = new GlassBox();
                disciplineResBox.init( 'disciplineResBox', '420px', '210px', 'hidden','',true, false);
                disciplineResBox.ipos();
                disciplineResBox.appear();
            }

            var stile = "top=10, left=10, width=750, height=500, status=no, menubar=no, toolbar=no scrollbars=no";

            function nuovaDisc()
            {
                location.href="nuovaDisciplinaWeb.php?disc=1";
            }

            function eliminaDisciplina(codice)
            {
                document.getElementById('codiceDisciplinaToDelete').value=codice;
                document.getElementById('eliminaDisc').submit();
            }
        </script>
    </head>
    <body>

        <form method="post" action="nuovoOperatoreListener.php" id="eliminaDisc">
            <input type="hidden" name="operation" value="eliminaDisc" />
            <input type="hidden" id="codiceDisciplinaToDelete" name="codiceDisciplina" value="" />
        </form>

        <?if(!isset ($_GET["noHead"]))
            include '../portal/header.php';
        else
{?>
        <center>
            <a href='javascript:history.go(-1);'><img src='../images/icons/back.ico' height='30' width='30' title='Indietro' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/utente/utente.php?codiceUtente=<?= $_COOKIE['codiceUtente']?>'><img src='../images/icons/PNG/Administrator.png' height='30' width='30' title='<?= $_COOKIE['username']?>' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/portal/newMenu.php'><img src='../images/icons/64/home.png' height='30' width='30' title='Home' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/utente/nuovaClasse.php'><img src='../images/icons/128/school.png' height='30' width='30' title='Nuova classe' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/report/searchStudents.php'><img src='../images/icons/128/people.png' height='30' width='30' title='Studenti' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/testManaging/newArgomento.php?codiceUtente=".$_COOKIE["codiceUtente"] ."'><img src='../images/icons/128/phonebook.png' height='30' width='30' title='Gestione Argomenti' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/testManaging/newQuestion.php'><img src='../images/icons/128/plus.png' height='30' width='30' title='Nuova domanda' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/report/reportQuestions.php'><img src='../images/icons/PNG/Document.png' height='30' width='30' title='Cerca Domande' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/testManaging/newTest_1.php'><img src='../images/icons/128/interact.png' height='30' width='30' title='Nuovo test' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/report/searchTest.php'><img src='../images/icons/128/pencil.png' height='30' width='30' title='Test' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/testManaging/reportLiveTest.php'><img src='../images/icons/128/vault.png' height='30' width='30' title='Test sottomessi' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/testManaging/reportPdfLiveTest.php'><img src='../images/icons/128/world.png' height='30' width='30' title='Verifica test' border='0'/></a>
            <a href='<?= $properties->getPath() ?>/portal/logout.php'><img src='../images/icons/PNG/logout.png' height='30' width='30' title='Logout' border='0'/></a>
        </center>
    <?}?>
        <center>
            <div id="disciplineBox">
                <div id="disciplineBoxCont">

                    <form method="post" action="nuovoOperatoreListener.php">
                        <input type="hidden" name="operation" value="nuovaDiscipliana" />
                        <input type="hidden" name="codiceUtente" value="<?= $_COOKIE['codiceUtente'] ?>" />
                        <table>
                            <tr>
                                <th>Discipline disponibili: </th>
                                <td>
                                    <select name="codiceDisciplina" id="disciplina">
                                        <?php
                                        while ($row = $result->fetch_row())
                                        {
                                            echo '<option value=' . $row[0]. '>' . $row[1]  . '</option>';
                                        }
                                        $result->close();
?>
                                    </select>
                                </td>
                                <td><input type="submit" value="Inserisci"/></td>
                            </tr>
                            <tr>
                                <td><input type="button" value="Nuova disciplina" onclick="javascript:nuovaDisc();" /> </td>
                            </tr>
                            <tr>
                        </table>
                    </form>



                </div>
            </div>
            <div id="disciplineResBox">
                <div id="disciplineResBoxCont">
                    <table>
                        <tr>
                            <th>Discipline inserite</th>
                        </tr>
                        <?
                        for($i=0;$i<count($disciplineUtente); $i++)
                        {
                                ?><tr><?
                                $disciplinaDesc = DisciplinaDataManager::getInstance()->getDisciplina($db, $disciplineUtente[$i]);

    $str = trim($disciplinaDesc->getNome()); ?>
                            <td>* <?= $str  ?></td>
                            <td><input type="button" value="Elimina" onclick="eliminaDisciplina(<?= $disciplinaDesc->getCodice()?>)"</td>
                        </tr>

    <?}?>



                    </table>


                </div>
            </div>
        </center>
    </body>
</html>
